<?php

require_once ROOT_LIBRARY_RESTFUL . DS . 'restful.php';
require_once ROOT_LIBRARY_KLOGGER . DS . 'klogger.php';

class error_handler extends restful {

    public function __construct() {
        $config = include ROOT_CONFIG;
        error_reporting($config['error']['error_reporting']);
    }

    public function handler_error($errno, $errstr, $errfile, $errline) {
        $log = KLogger::instance(ROOT_DATA_LOG . DS . 'internal_error', KLogger::DEBUG);
        $log->logError($errno . ' | ' . $errstr . ' | ' . $errfile . ' | ' . $errline);
        $this->response(json_encode(array('error' => 1, 'messsage' => $errstr, 'data' => '')));
    }

    public function handler_exception($exception) {
        $log = KLogger::instance(ROOT_DATA_LOG . DS . 'internal_error', KLogger::DEBUG);
        $log->logError($exception->getMessage());
        $this->response(json_encode(array('error' => 1, 'messsage' => $exception->getMessage(), 'data' => '')));
    }

    protected function router() {
        
    }

}

$error_handler = new error_handler();
set_error_handler(array($error_handler, 'handler_error'));
set_exception_handler(array($error_handler, 'handler_exception'));

?>